<!DOCTYPE html>
<html>

<head>
    <!-- baidu_tongji -->
    <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?a4f6375a0eb56b034134800adbfae77d";
      var s = document.getElementsByTagName("script")[0]; 
      s.parentNode.insertBefore(hm, s);
    })();
    </script>
    <!-- Favicons -->
    <link
        href=""
        rel="shortcut icon" type="image/x-icon">
    <!-- UTF-8 -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>文件异或操作</title>
    <!-- 引入 Bootstrap 5.1.1 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/css/bootstrap.min.css">
    <script>
        function xorFileContent() {
            const xorValue = 0x5D;
            const fileInput = document.getElementById('fileInput');
            const file = fileInput.files[0];

            if (!file) {
                alert("请选择一个文件！");
                return;
            }

            const reader = new FileReader();
            reader.onload = function (event) {
                const fileContent = new Uint8Array(event.target.result);
                const xorResult = new Uint8Array(fileContent.length);

                for (let i = 0; i < fileContent.length; i++) {
                    xorResult[i] = fileContent[i] ^ xorValue;
                }

                const xorBlob = new Blob([xorResult]);
                const xorURL = URL.createObjectURL(xorBlob);

                const downloadLink = document.createElement('a');
                downloadLink.href = xorURL;
                downloadLink.download = "xor_" + file.name;
                downloadLink.click();

                URL.revokeObjectURL(xorURL);
            };

            reader.readAsArrayBuffer(file);
        }
    </script>
</head>

<body>
    <div class="container mt-3">
        <h1 class="mb-4">文件异或操作</h1>
        <div class="input-group mb-3">
            <input type="file" id="fileInput" class="form-control" accept=".moc.prefab">
            <button class="btn btn-primary" onclick="xorFileContent()">异或并下载</button>
        </div>
        <div>
            本网页仅用于学习用途，由此产生的所有纠纷均由使用者自行承担！
        </div>
    </div>

    <!-- 引入 Bootstrap 5.1.1 JS 文件，用于处理样式 -->
    <script src="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/js/bootstrap.bundle.min.js"></script>
</body>

</html>
